<!DOCTYPE html>
<html>

<head>
    <meta charset="UTF-8">
    <meta http-equiv="X-UA-Compatible" content="IE=9; IE=8; IE=7; IE=EDGE">
    <meta http-equiv="X-UA-Compatible" content="IE=EmulateIE7"/>
    <title>设置-个人信息</title>
    <link rel="icon" href="/assets/img/favicon.ico">

    <link rel="stylesheet" type="text/css" href="css/webbase.css"/>
    <link rel="stylesheet" type="text/css" href="css/pages-seckillOrder.css"/>
    <!-- 引入样式 -->
    <link rel="stylesheet" href="./js/element-css.css">
</head>

<body>
<!--页面顶部，由js动态加载-->
<script type="text/javascript" src="plugins/jquery/jquery.min.js"></script>

<script type="text/javascript" src="js/plugins/jquery.easing/jquery.easing.min.js"></script>
<script type="text/javascript" src="js/plugins/sui/sui.min.js"></script>
<script type="text/javascript" src="js/plugins/jquery-placeholder/jquery.placeholder.min.js"></script>
<script type="text/javascript" src="js/widget/nav.js"></script>
<!--日期选择-->
<script type="text/javascript" src="js/plugins/birthday/birthday.js"></script>
<!--城市数据-->
<script type="text/javascript" src="js/plugins/citypicker/distpicker.data.js"></script>
<!--关联器-->
<script type="text/javascript" src="js/plugins/citypicker/distpicker.js"></script>
<!--主js-->
<script type="text/javascript" src="js/pages/main.js"></script>
<!--上传图片-->
<!--
<script type="text/javascript" src="js/plugins/upload/uploadPreview.js"></script>
-->
<div class="nav-bottom"></div>
<script type="text/javascript">$(".nav-bottom").load("top.html");</script>
<script type="text/javascript">
    $(function () {
        $("#service").hover(function () {
            $(".service").show();
        }, function () {
            $(".service").hide();
        });
        $("#shopcar").hover(function () {
            $("#shopcarlist").show();
        }, function () {
            $("#shopcarlist").hide();
        });

    })
</script>
<script>
    $(function () {
        $.ms_DatePicker({
            YearSelector: "#select_year2",
            MonthSelector: "#select_month2",
            DaySelector: "#select_day2"
        });
    });
</script>
</body>

<!--header-->
<div id="account">
    <div class="py-container">
        <div class="yui3-g home">
            <!--左侧列表-->
            <div class="yui3-u-1-6 list">

                <div class="person-info">
                    <div class="person-photo"><img :src="img" alt="" style="width:50px; height:50px; border-radius:50%; "></div>
                    <div class="person-account">
                        <span class="name">{{user.nickname}}</span>
                        <span class="safe">账户安全</span>
                    </div>
                    <div class="clearfix"></div>
                </div>
                <div class="list-items">
                    <dl>
                        <dt><i>·</i> 订单中心</dt>
                        <dd><a href="home-index.html">我的订单</a></dd>
                        <dd><a href="home-order-pay.html">待付款</a></dd>
                        <dd><a href="home-order-send.html">待发货</a></dd>
                        <dd><a href="home-order-receive.html">待收货</a></dd>
                        <dd><a href="home-order-evaluate.html">待评价</a></dd>
                    </dl>
                    <dl>
                        <dt><i>·</i> 我的中心</dt>
                        <dd><a href="home-person-collect.html">我的收藏</a></dd>
                        <dd><a href="home-person-footmark.html">我的足迹</a></dd>
                    </dl>
                    <dl>
                        <dt><i>·</i> 物流消息</dt>
                    </dl>
                    <dl>
                        <dt><i>·</i> 设置</dt>
                        <dd><a href="home-setting-info.html" class="list-active">个人信息</a></dd>
                        <dd><a href="home-setting-address.html">地址管理</a></dd>
                        <dd><a href="home-setting-safe.html">安全管理</a></dd>
                    </dl>
                </div>
            </div>
            <!--右侧主内容-->
            <div class="yui3-u-5-6">
                <div class="body userInfo">
                    <ul class="sui-nav nav-tabs nav-large nav-primary ">
                        <li class="active"><a href="#one" data-toggle="tab">基本资料</a></li>
                        <li><a href="#two" data-toggle="tab">头像照片</a></li>
                    </ul>
                    <div class="tab-content" id="userInfoApp">
                        <div id="one" class="tab-pane active">
                            <form id="form-msg" class="sui-form form-horizontal" id="userInfoForm">
                                <div class="control-group">
                                    <label for="nickname" class="control-label">昵称：</label>
                                    <div class="controls">
                                        <input type="text" v-model="user.nickname" name="nickname" id="nickname"
                                               placeholder="昵称">
                                    </div>
                                </div>
                                <div class="control-group">
                                    <label for="inputGender" class="control-label">性别：</label>
                                    <div class="controls">
                                        <input type="radio" name="gender" v-model="user.gender" value="1"><label>&nbsp;&nbsp;男</label>
                                        &nbsp;&nbsp;
                                        <input type="radio" name="gender" v-model="user.gender" value="2"><label>&nbsp;&nbsp;女</label>
                                    </div>
                                </div>
                                <div class="control-group">
                                    <label for="inputPassword" class="control-label">生日：</label>
                                    <div class="controls">
                                        <select id="select_year2" name="birthday[year]" v-model="user.birthday[0]"
                                                rel="1990"></select>年
                                        <select id="select_month2" name="birthday[month]" v-model="user.birthday[1]"
                                                rel="4"></select>月
                                        <select id="select_day2" name="birthday[day]" v-model="user.birthday[2]"
                                                rel="3"></select>日
                                    </div>
                                </div>


                                <div class="control-group">
                                    <label for="inputPassword" class="control-label">所在地：</label>
                                    <div class="controls">
                                        <div id="distpicker">
                                            <div class="form-group area">
                                                <select class="form-control" name="address[province]"
                                                        v-model="user.address[0]" id="province1"></select>
                                            </div>
                                            <div class="form-group area">
                                                <select class="form-control" name="address[city]"
                                                        v-model="user.address[1]" id="city1"></select>
                                            </div>
                                            <div class="form-group area">
                                                <select class="form-control" name="address[district]"
                                                        v-model="user.address[2]" id="district1"></select>
                                            </div>
                                        </div>
                                    </div>
                                </div>
                                <div class="control-group">
                                    <label for="inputJob" class="control-label">职业：</label>
                                    <div class="controls"><span class="sui-dropdown dropdown-bordered select">
                                        <span class="dropdown-inner"><a role="button" data-toggle="dropdown" href="#"
                                                                        class="dropdown-toggle">
                                                <input name="job" v-model="user.job" value="" type="hidden"
                                                       data-rules="required">
                                            <i class="caret"></i><span class="userJobName">请选择</span></a>
                                            <ul id="menu4" role="menu" aria-labelledby="drop4"
                                                class="sui-dropdown-menu">
                                                <li role="presentation">
                                                    <a role="menuitem" class="userJob" tabindex="-1"
                                                       href="javascript:void(0);" value="bj">程序员</a></li>
                                                <li role="presentation">
                                                    <a role="menuitem" class="userJob" tabindex="-1"
                                                       href="javascript:void(0);" value="sb">产品经理</a></li>
                                                <li role="presentation">
                                                    <a role="menuitem" class="userJob" tabindex="-1"
                                                       href="javascript:void(0);" value="sb">UI设计师</a></li>
                                            </ul>
                                            </span>
                                            </span>
                                    </div>
                                </div>
                                <div class="control-group">
                                    <label for="sanwei" class="control-label"></label>
                                    <div class="controls">
                                        <button type="submit" id="sanwei" class="sui-btn btn-primary" @click="submit">
                                            立即注册
                                        </button>
                                    </div>
                                </div>
                            </form>
                        </div>
                        <div id="two" class="tab-pane">

                            <div class="new-photo">
                                <p>当前头像：</p>
                                <el-upload :action="uploadPath" :data="ossData" :show-file-list="false"
                                           :before-upload="before" :on-success="uploadSuccess" :on-remove="handleRemove">
                                      <img class="photo" :src="img"/>

                                </el-upload>

                                <!--<div class="upload">
                                    <img id="imgShow_WU_FILE_0" width="100" height="100" src="img/_/photo_icon.png"
                                         alt="头像">
                                    <input type="file" id="up_img_WU_FILE_0" @click="imgClick"/>
                                </div>-->
                            </div>
                        </div>
                    </div>

                </div>
            </div>
        </div>
    </div>
</div>

<!-- 底部栏位 -->
<!--页面底部，由js动态加载-->
<div class="clearfix footer"></div>
<script type="text/javascript">$(".footer").load("foot.html");</script>
<!--页面底部END-->

<!--页面顶部，由js动态加载-->
<script src="./js/vue/vue.js"></script>
<script src="./js/axios.min.js"></script>
<!-- 引入组件库 -->
<script src="./js/element-ui.js"></script>
<script src="./js/common.js"></script>
<script src="./js/pages/shortcut.js"></script>
<script src="./js/pages/top.js"></script>
<script src="./js/pages/copyright.js"></script>
<script src="./js/pages/foot.js"></script>
<script src="./js/pages/side-panel.js"></script>
<script src="./js/plugins/jquery/jquery.cookie.js"></script>
<script type="text/javascript">
    var userInfoApp = new Vue({
        el: "#account",
        data: {
            user: {
                nickname: '',
                gender: '1',
                birthday: [],
                address: [],
                job: ''
            },
            img: "img/_/photo_icon.png",
            check: {
                username: false
            },
            ossData: {
                policy: '',
                OSSAccessKeyId: '',
                signature: '',
                key: ''
            },
            uploadPath: 'http://leyou4bucket.oss-cn-shanghai.aliyuncs.com',
            disabled: false,
        },
        created() {
            //查询用户详情
            ly.http.get("/user/auth/detail").then(resp => {
                if (resp.data != undefined && resp.data != null && resp.data !== "") {
                    this.user = resp.data;

                    if (resp.data.img != "" && resp.data.img != null) {
                        this.img = resp.data.img;
                    } else {
                        this.img = "/img/_/photo_icon.png"
                    }
                    if (resp.data.addressList != null && resp.data.addressList.length > 1) {
                        this.user.address = resp.data.addressList;
                        $("#province1").val(resp.data.addressList[0]).change();
                        $("#city1").val(resp.data.addressList[1]).change();
                    } else {
                        this.user.address = [];
                    }
                    if (resp.data.birthday != null && resp.data.birthday.length > 1) {
                        this.user.birthday = resp.data.birthdayList;
                    } else {
                        this.user.birthday = [];
                    }
                    if (resp.data.job != null && resp.data.job.length > 1) {
                        var $1 = $(".userJob[value=" + resp.data.job + "]");
                        $1.parent().addClass("active");
                        $('.userJobName').text($1.text());
                    }
                }
            });
        },
        methods: {
            submit() {
                //保存用户数据
                var formData = this.user;
                formData.birthday = this.user.birthday.length > 1 ? this.user.birthday.join("-") : "";
                formData.address = this.user.address.length > 1 ? this.user.address.join(" ") : '';
                formData.job = $("#userJobInput").val();
                // 校验通过，提交表单
                leyou.http.post("/user/auth/detail/save", leyou.stringify(formData))
                    .then(resp => {
                        console.log(resp);
                    }).catch(() => alert("注册失败！"))
            },
            async before(file) {
                //console.log(file)
                const {data} = await axios.get("http://api.leyou.com/auth/ali/oss/signature");
                this.ossData.key = data.dir + "/" + file.uid + ".jpg";
                this.ossData.policy = data.policy;
                this.ossData.OSSAccessKeyId = data.accessId;
                this.ossData.signature = data.signature;
            },
            uploadImg() {
                leyou.http.post("/user/auth/detail/saveimg", leyou.stringify({img: this.img}))
                    .then(resp => {
                        console.log(resp);
                    }).catch(() => alert("上传失败！"))
            },
            uploadSuccess(response, file, fileList) {
                var fileName = file.uid.toString() + ".jpg";
                var map = {
                    uid: file.uid,
                    url: "https://leyou4bucket.oss-cn-shanghai.aliyuncs.com/ly-images/" + fileName
                };
                this.img = map.url;
                this.uploadImg();
            },
            handleRemove(file) {
                //console.log(file);
                //console.log(this.files);
                var fileName = file.uid.toString() + ".jpg";
                var map = {
                    uid: file.uid,
                    url: "https://leyou4bucket.oss-cn-shanghai.aliyuncs.com/ly-images/" + fileName
                };
                var index = this.files.indexOf(map);
                this.files.splice(index, 1);
            }
        }
    });
</script>

</html>